#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

void GetMinNum(int array[], int arrayLength, int num);

int main()
{
	int array[] = {1, 2, 3, 4, 5, 6, 7, 8};
	GetMinNum(array, sizeof(array)/sizeof(array[0]), 4);
	system("pause");
	return 0;
}

void GetMinNum(int array[], int arrayLength ,int num)
{
	vector<int>minVector;
	int min = - (1 << 31);
	for (int i = 0; i < arrayLength; ++ i)
	{
		if (i < num)
		{
			minVector.push_back(array[i]);
			if (i == num - 1)
			{
				//sort vector
				for (int j = 0; j < minVector.size() - 1; ++ j)
				{
					if (minVector[j] > minVector[j + 1])
					{
						swap(minVector[j], minVector[j + 1]);
					}
				}
			}
		}
		else
		{
			bool isInsert = false;
			for (vector<int>::iterator iter = minVector.begin(); iter != minVector.end(); ++ iter)
			{
				if (array[i] < *iter)
				{
					minVector.insert(iter, array[i]);
					isInsert = true;
					break;
				}
			}
			if (isInsert)
			{
				minVector.pop_back();
				isInsert = false;
			}
		}
	}
	for(vector<int>::iterator iter = minVector.begin(); iter != minVector.end(); ++ iter)
	{
		cout << *iter << "  ";
	}
	cout<<endl;
}